import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $http, $fn, $Lazy } = window
// ===================================================================== $Lazy
const Printer 			= $Lazy.hook(()=>import('#private/printer'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data: [],
		formData:[
			{ label: '开始条码', 	name:'start_code', 	full:true,	required:true },
			{ label: '结束条码', 	name:'end_code', 	full:true,	required:true },
			{ label: '打印实验号',	name: 'is_printer', 	half:true, 	type: 'radio',	 value:'1',	data:[{value:'1',name:'是'},{value:'0',name:'否'}]},
			{ label: '打印份数', 	name:'number',	half:true,	type:'number',	value:1 },
		]
	}
	
	open = ()=> {
		this.formRef.setValue({is_printer:'1',number:1})
		this.modal.open({formRef: this.formRef})
	}
	
	batchShelf = ()=> {		/* 批量上架添加异步 2021-8-24 --马婷 */
		const submitData = this.formRef.getValue()
		const {start_code,end_code,is_printer,number} = submitData
		$http.submit(null,'shelf/singbatchupshelf',{ param:{...submitData}, loading:true}).then(data=>{
			$fn.msg.success('批量上架成功')
			this.modal.close()
			this.props.onRefresh()
			$http.submit(null,'shelf/printshelf',{ param:{start_code,end_code}, loading:false}).then(data=>{
				if(+is_printer){
					if(+number>=1){
						this.printerRef.printer({ code: 50104, data, loading:false,link:+number})
					}
				}
			})
		})
		window.onRefresh = () => {		 
			this.modal.close()
			this.props.onRefresh()
			$http.submit(null,'shelf/printshelf',{ param:{start_code,end_code}, loading:false}).then(data=>{
				if(+is_printer){
					if(+number>=1){
						this.printerRef.printer({ code: 50104, data, loading:false,link:+number})
					}
				}
			})
		}
	}
	
	render(){
		return FormModal.call(this, {title:'批量上架', labelWidth:'s6', width:700, api:'',onSubmit: this.batchShelf,
			suffix:(<Printer onRef = { ref => this.printerRef = ref } hasBtn = {false} tips = {true}   />)
		} )
	}
}

export default Index

/* 标本上架增加批量上架 2021-7-28  --马婷 */